package com.foreveross.taskservice.infra.hbase;

import java.io.Serializable;

import com.foreveross.taskservice.infra.hbase.jpa.IBaseRepository;
import com.foreveross.taskservice.infra.util.SpringHelper;

/**
 * 实例工厂
 * @author xiangsf 2013-1-24
 *
 */
public class InstanceFactory {
	
	public static <T extends IBaseEntity> T getInstance(Class<T> clazz, Serializable id) throws Exception{
		if(id == null) return getNewInstance(clazz);
		IBaseRepository baseRepository	= clazz.newInstance().getBaseEntityRepository();
		return baseRepository.find(clazz, id);
	}
	
	public static <T extends IBaseEntity> T getNewInstance(Class<T> clazz) throws Exception{
		return clazz.newInstance();
	}
	
	public static <T> T getInstance(Class<T> clazz){
		return SpringHelper.getBean(clazz);
	}
	
	public static <T> T getInstance(Class<T> clazz, String name){
		return SpringHelper.getBean(clazz, name);
	}
	
	public static Object getInstance(String name){
		return SpringHelper.getBean(name);
	}
}
